<template>
	<view class="main">
		<view class="">
			<view class="">
				<zzx-calendar @selected-change="datechange"></zzx-calendar>
				<!-- <ping-cal @chooseDay="chooseDay"></ping-cal> -->
			</view>
			<view class="">
				<view class="empty_list" v-if="emptyJob">
					<u-image width="335rpx" height="320rpx" :src="actionImg"></u-image>
					<view class="empty_text">
						{{emptyText}}
					</view>
				</view>
				<view class="job_content" v-if="!emptyJob">
					<view class="job_list" v-for="(v,n) in list">
						<view class="">
							<view class="">
								{{v.jobStartTime}}
							</view>
							<view class="job_title">
								<view class="job_title_icon" :class="{yellow:v.jobType == 2}">{{jobType(v.jobType)}}
								</view>
								<view class="">
									{{v.jobName}}
								</view>
							</view>
							<view class="">
								目标患者：{{v.targetCustomerNum}}人
							</view>
							<view class="">
								{{v.jobContent}}
							</view>
						</view>
				
				
						<view class="job_action">
							<view class="flex">
								<view class="job_left"  @click="myAction(v)">
									执行
								</view>
								<view class="job_right" @click="overView(v)">
									忽略
								</view>
							</view>
						
							<view class="" @click="details(v)">
								详情
							</view>
						</view>
				
					</view>
					<view style="padding-top: 40rpx;padding-bottom: 40rpx;">
						<u-loadmore :status="status" v-if="!empty" />
					</view>
				</view>
			</view>
		</view>

		<u-modal v-model="show" :show-title="false" :content="content"
			:content-style="{'fontSize':'32rpx','lineHeight': '1.5','fontWeight':'bold'}" cancel-color="#333333"
			:show-cancel-button="true" confirm-color="#4DC0D9" @confirm="Userconfirm" @cancel="cancel"
			:cancel-style="{'borderRight':'1px solid #f8f8f8'}">
		</u-modal>
		<go-nav></go-nav>
	</view>
</template>

<script>
	import {
		indexJobList,
		executeOrIgnoreFollowupPlanJob,
		getFollowupPlanJobByPlanId
	} from '@/api/index.js'
	import pageMixin from '@/utils/pageMixin.js'
	export default {
		mixins: [pageMixin],
		data() {
			return {
				show: false,
				emptyJob: false,
				actionImg: require('@/static/img/No_follow.png'),
				emptyText: '暂无待办事项',
				content: '',
				lists: [{
						'time': '2024-07-15 11:03',
						'title': '糖尿病轻度患者恢复情况跟踪',
						'job': '定时',
						'num': 20,
						'subTitle': '糖尿病轻度患者恢复情况跟踪调查表',
						'ignore': false,
						'action': false
					},
					{
						'time': '2024-07-15 11:03',
						'title': '糖尿病轻度患者恢复情况跟踪',
						'job': '周期',
						'num': 32,
						'subTitle': '糖尿病轻度患者恢复情况跟踪调查表',
						'ignore': false,
						'action': false
					},
					{
						'time': '2024-07-15 11:03',
						'title': '糖尿病轻度患者恢复情况跟踪',
						'job': '定时',
						'num': 20,
						'subTitle': '糖尿病轻度患者恢复情况跟踪调查表',
						'ignore': false,
						'action': false
					},
				],
				userList: [],
				navChoose: 0, //0待执行   2待评估
				currentDay: '',
				currentObj:''  //当前选中的要执行对象
			}
		},
		computed: {
			jobType(type) {
				return (type) => type == 1 ? '定时' : '周期'
			}
		},
		onShow() {
			this.currentDay = this.padDay(new Date()) //当天日期
			//console.log(this.currentDay);
		},
		onLoad() {

		},
		methods: {
			async getMyList(obj) { //请求,这个最好在使用那个组件中使用，这个地方可以扩展接参数
				// 例如， {..obj,id:15}
				let res = await indexJobList(this.navChoose, {
					...obj,
					date: this.currentDay
				})
				let rows = res.rows.length
				if (rows == 0) {
					this.emptyJob = true
				} else {
					this.emptyJob = false
				}
				// this.teamNumber = res.total //单独需要赋值的地方
				return res
			},
			async confirm() { //确定忽略
				let params = {
					executeOrIgnore: 'ignore',
					jobId: this.currentObj.id
				}
				let res = await executeOrIgnoreFollowupPlanJob(params)
				if (res.code == 200) {
					this.clearPageStatus()
					await this.getTeam()
				}
				// this.list.splice(n, 1)
				// console.log(123);
				// this.list = this.list.filter(v => v.ignore != true)
				// if (this.list.length == 0) this.emptyJob = true
			},
			cancel() {

			},
			async overView(obj) { //忽略弹窗
				this.currentObj = obj
				this.show = true //忽略弹窗
				this.content = `忽略后将不再对目标患者执行“${obj.jobName}”任务，确定要忽略该任务吗？`
			},
			async myAction(obj) { //执行
				let params = {
					executeOrIgnore: 'execute',
					jobId: obj.id
				}
				let res = await executeOrIgnoreFollowupPlanJob(params)
				if (res.code == 200) {
					uni.showLoading({
						title: "加载数据中"
					})
					setTimeout(async() => {
						uni.hideLoading()
						this.clearPageStatus()
						await this.getTeam()
					},3000)
				}
			},
			async details(obj){
				let res = await getFollowupPlanJobByPlanId(obj.planId)
				if (res.code == 200) {
					this.$store.commit('SHOWJOBLISTALL', res.data)
				}
				if (obj.planId) { //有值就是修改
					if (obj.jobType == 1) this.$store.commit('JOBTYPEShow', '定时任务')
					if (obj.jobType == 2) this.$store.commit('JOBTYPEShow', '周期任务')
				}
				let ress = await this.$store.dispatch('editJobList', obj.jobName)
				if (ress.find) {
					uni.navigateTo({
						url: `/pages/follow/rulejobview?edit=1&jobName=${obj.jobName}`
					})
				}
				// uni.navigateTo({
				// 	url:`/pages/follow/rulejobview?planId=${obj.planId}`
				// }) 
				//console.log(obj,'详情');
			},
			goPinggu() {
				uni.navigateTo({
					url: '/pages/index/pinggu'
				})
			},
			datechange(day){
				this.currentDay = day.fullDate
				this.clearPageStatus()
				this.getTeam()
				//console.log(day);
			},
			
			padDay(day) {
				let chooseDay
				if (day instanceof Date) { //对接就直接赋值，字符串就转化为时间对象
					chooseDay = day
				} else {
					chooseDay = new Date(day)
				}
				let year = chooseDay.getFullYear()
				let month = String(chooseDay.getMonth() + 1).padStart(2, '0')
				let days = String(chooseDay.getDate()).padStart(2, '0');
				return `${year}-${month}-${days}`
			},
			chooseDay(day) {  //自己修改的，废弃了
				let choose = this.padDay(day)
				this.currentDay = choose
				this.clearPageStatus()
				this.getTeam()
			},
			Userconfirm(list) {
				console.log(this.userSelectLength, this.userList.length);
				const arr = this.$u.deepClone(list)
				this.userSelectLength = list.length
				this.userList = arr.filter(v => v.check == true) //选中人员
				if (this.userSelectLength !== this.userList.length &&
					this.userList.length > 0) {
					const arr = []
					//this.QueryParams.searchType = '' //有了查询条件，searchType就不能为全部了
					this.userList.map(v => arr.push(v.userId))
					this.QueryParams.userIds = arr

				} else if (this.userList.length == 1) { //只有一条的情况下
					const arr = []
					this.userList.map(v => arr.push(v.userId))
					this.QueryParams.userIds = arr

				} else {
					//this.QueryParams.searchType = '' //有了查询条件，searchType就不能为全部了
					this.QueryParams.userIds = null //这里写null是因为子组件watch值需要改变才能触发，传了null会被请求方法过滤掉。没传等于默认所有
				}
				this.showUser = false
			},
		},
	}
</script>

<style lang="scss" scoped>
	.main {
		background-color: #F8F8F8;
		min-height: 130vh;
		.job_content {
			background-color: #f8f8f8;
			margin: 24rpx 24rpx 8rpx 24rpx;
			border-radius: 20rpx;
			padding-bottom: 150rpx;

			.job_list {
				background-color: white;
				padding: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-size: 32rpx;
				color: #999999;
				line-height: 1.5;
				margin-bottom: 20rpx;
				border-radius: 20rpx;

				.job_title {
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 36rpx;
					color: #212121;
					line-height: 1.5;
					display: flex;
					align-items: center;

					.job_title_icon {
						padding: 0 8rpx;
						background: #4DC0D9;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #FFFFFF;
						line-height: 36rpx;
						margin-right: 16rpx;
					}

					.yellow {
						background-color: #FF8D07;
					}
				}
			}

			.job_action {
				margin-top: 24rpx;
				display: flex;
				color: #4DC0D9;
				justify-content: space-between;

				.job_left {
					margin-right: 48rpx;
				}
			}

		}
	}

	.empty_list {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.empty_text {
			font-weight: 500;
			font-size: 36rpx;
			color: #C7C7C7;
			line-height: 1.5;
			text-align: center;
		}
	}
	
</style>
